package org.starapp.rbac.rest;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

public class RestPut {

	/**
	 * @param args
	 * add
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			// TODO Auto-generated method stub
			DefaultHttpClient httpclient = new DefaultHttpClient();
			// 代理的设置  
//			HttpHost proxy = new HttpHost("192.168.1.2", 8888);
//			httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
//					proxy);
			// 目标地址  
			HttpPost httppost = new HttpPost(
					"http://localhost:8888/starapp-demo/api/v1/users/update");
			System.out.println("请求: " + httppost.getRequestLine());
			// 构造最简单的字符串数据  
			StringEntity reqEntity = new StringEntity("{\"userId\": \"admin\",\"userName\": \"hediwang\"}");
			
			// 设置类型  
			reqEntity.setContentType("application/json");
			// 设置请求的数据  
			httppost.setEntity(reqEntity);
			// 执行  
			       
			       HttpResponse response = httpclient.execute(httppost);
			       System.out.println("======="+EntityUtils.toString(response.getEntity()));
			       httpclient.getConnectionManager().shutdown();
		} catch (Exception e) {
			// TODO: handle exception
		}  
	}

}
